let text = 'We Love Programming!'

let text_box = document.querySelector('.text')
// 暂停
let pause = false

let speed = 300
// 文本裁剪 索引
let index = 1
function writeText(){
  // text_box.innerText = text.slice(0, index)
  text_box.innerText = text.substring(0, index)
  index++
  if(index > text.length){
    index = 1
  }
  if(!pause) {
    setTimeout(writeText,speed)
  }
  

}

writeText()

function setSpeed(e){
  speed = 300 / e.value
}

text_box.addEventListener('click',function(){
  pause = !pause
  if(!pause){
    writeText()
  }
})